<?php
// $Id: TextFieldInput.php 27 2010-11-16 12:49:54Z mjohnson60@gmail.com $


/**
 * Enter description here ...
 * 
 * @author markjohnson
 * @version 1.0
 * @copyright Copyright (c) 2010, markjohnson
 * @license http://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
 *
 */
class TextFieldInput extends FormElement
{
	/**
	 * Enter description here ...
	 * 
	 * @var unknown_type
	 */
	var $size = 60;
	
	/**
	 * Enter description here ...
	 * 
	 * @var unknown_type
	 */
	var $max_length = 128;
	
	/**
	 * @var unknown_type Enter description here ...
	 */
	var $field_prefix = '';
	
	/**
	 * @var unknown_type Enter description here ...
	 */
	var $field_suffix = '';
	
	/**
	 * @var unknown_type Enter description here ...
	 */
	var $placeholder = '';

	/**
	 * Enter description here ...
	 * 
	 * @param string $name
	 * @param string $value
	 * @param string $id
	 * @param FormElement $parent
	 * @param array $attributes
	 * @param int $size
	 * @param int $max_length
	 */
	function __construct($name, $value = NULL, $id = NULL, $parent = NULL, $attributes = array(), $size = 60, $max_length = 255)
	{
		$this->type = 'textfield';
		$this->size = $size;
		$this->max_length = $max_length;
		
		if (is_array($value))
		{
			parent::__construct($value, $name);
		}
		else
		{
			parent::__construct(NULL, $name, $value, $id, $parent, $attributes);
		}
	}

	/* 
	 * @see FormElement::_compile()
	 */
	public function _compile()
	{
		return $this->render();
	}

	/* 
	 * @see FormElement::render()
	 */
	public function render()
	{
		$output = '';
		
		if (!empty($this->field_prefix))
		{
			$output .= '<span class="field-prefix">' . $this->field_prefix . '</span>';
		}
		
		$this->addHtmlClasses(array(
			'form-text'
		));
		
		$output .= '<input type="text" maxlength="' . $this->max_length . '" name="' . $this->name . '" id="' . $this->id . '" size="' . $this->size . '" placeholder="' . check_plain($this->placeholder) . '" value="' . (isset($this->value) ? check_plain($this->value) : '') . '"' . (empty($this->attributes) ? '' : attributes($this->attributes)) . ' />';
		
		if (!empty($this->field_suffix))
		{
			$output .= '<span class="field-suffix">' . $this->field_suffix . '</span>';
		}
		
		return parent::render($output);
	}
}
